<?php
class DBMySQLi{
	private $_connect;
	private $_error = 0;
	public function __construct(){
		
		$this->_connect = 	new  mysqli('54.255.152.199', 'cddevuser8', 'DevsqdI$CoUnt');
		
		if ($this->_connect->connect_error) {
			throw new ErrorException('Error: Could not make a database link (' . $this->_connect->connect_errno. ') ' . $this->_connect->connect_error);
		}
		$this->_connect->autocommit(false);
		$this->_connect->set_charset("utf8");
	}
	
	public function __destruct(){
		if(!$this->_connect->connect_error){
			if($this->_error == 0){
				$this->_connect->commit();
			}else{
				$this->_connect->rollback();
			}
			$this->_connect->close();
		}
		
	}
	
	public function commit(){
		$this->_connect->commit();	
	}
	
	public function rollback(){
		$this->_connect->rollback();
	}
	
	public function query($sql){
		$query = $this->_connect->query($sql);
		if (!$this->_connect->errno){
			if (isset($query->num_rows)) {
				$data = array();
	
				while ($row = $query->fetch_assoc()) {
					$data[] = $row;
				}
	
				$result = new stdClass();
				$result->num_rows = $query->num_rows;
				$result->row = isset($data[0]) ? $data[0] : array();
				$result->rows = $data;
	
				unset($data);
				$query->close();
	
				return $result;
			} else{
				return true;
			}
		} else {
			$this->_error--;
			throw new ErrorException('Error: ' . $this->_connect->error . '<br />Error No: ' . $this->_connect->errno . '<br />' . $sql);
			exit();
		}
	}
	
}

$connect = new DBMySQLi();